package com.ktjy.config;

import jakarta.annotation.PostConstruct;
import org.activiti.engine.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ActivitiConfig {

    @Autowired
    private RepositoryService repositoryService;

    @PostConstruct
    public void deployProcess() {
        // 检查是否已经部署
        long count = repositoryService.createProcessDefinitionQuery()
                .processDefinitionKey("Activity2")
                .count();

        if (count == 0) {
            // 部署流程定义
            repositoryService.createDeployment()
                    .addClasspathResource("bpmn/Activity2.bpmn20.xml")
                    .name("Activity2流程定义")
                    .deploy();
        }
    }
}